home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-27 | 5.7 KB | 240 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LNotificationTask.cp © 1995, Éric Forget. All rights reserved.
- // ===========================================================================
- //
- // ************************************************************************
- // * *
- // * Before using this code you should read the "License Agreement" *
- // * document and agree with it. *
- // * *
- // ************************************************************************
- //
- // LNotificationTask is a wrapper class for the Notification Manager.
- //
- // ---------------------------------------------------------------------------
- //
- // Instruction Notes:
- // -----------------
- //
- // 1) Create a LNotificationTask object with the right arguments. That's all!
- //
- // ---------------------------------------------------------------------------
-
- #include "LNotificationTask.h"
-
- #include <String_Utils.h>
- #include <UMemoryMgr.h>
-
-
-
- // ---------------------------------------------------------------------------
- // • Static members
- // ---------------------------------------------------------------------------
-
- NMUPP LNotificationTask::sTaskUPP = NewNMProc(LNotificationTask::TaskUPP);
-
-
- // ---------------------------------------------------------------------------
- // • LNotificationTask
- // ---------------------------------------------------------------------------
-
- LNotificationTask::LNotificationTask(
- StringPtr inDescriptor,
- ResIDT inStringID,
- ResIDT inIconFamilyID,
- Handle inSoundH,
- Int16 inMark,
- Boolean inDeleteOnCompletion)
-
- : LTask(0, 0, inDeleteOnCompletion)
- {
- Handle iconHandle = nil;
-
-
- if(inDescriptor != nil) {
-
- ::CopyPStr(inDescriptor, mDescriptor);
-
- } else if(inStringID != 0) {
-
- StringHandle stringH = ::GetString(inStringID);
- StHandleLocker locker((Handle)stringH);
-
- ::CopyPStr(*stringH, mDescriptor);
-
- } else {
-
- mDescriptor[0] = 0;
- }
-
-
- if(inIconFamilyID != -1) {
-
- ::GetIconSuite(&iconHandle, inIconFamilyID, svAllSmallData);
- }
-
- mNoteTask.task.nmResp = sTaskUPP;
- mNoteTask.task.qType = nmType;
- mNoteTask.task.nmIcon = iconHandle;
- mNoteTask.task.nmMark = inMark;
- mNoteTask.task.nmSound = inSoundH;
- mNoteTask.task.nmRefCon = 0;
- mNoteTask.task.nmStr = mDescriptor[0] ? mDescriptor : nil;
-
-
- #if !GENERATINGCFM
- mNoteTask.A5World = ::SetCurrentA5();
- #endif
- mNoteTask.noteTask = this;
-
- ::GetCurrentProcess(&mApplicationPSN);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~LNotificationTask
- // ---------------------------------------------------------------------------
-
- LNotificationTask::~LNotificationTask()
- {
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartTask
- // ---------------------------------------------------------------------------
-
- void
- LNotificationTask::StartTask()
- {
- if(!IsExecuting()) {
-
- LTask::StartTask();
-
- mUserHasSeenNote = false;
- ::NMInstall((NMRecPtr)&mNoteTask);
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • StopTask
- // ---------------------------------------------------------------------------
-
- void
- LNotificationTask::StopTask()
- {
- if(IsExecuting()) {
-
- ::NMRemove((NMRecPtr)&mNoteTask);
-
- LTask::StopTask();
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • TaskUPP
- // ---------------------------------------------------------------------------
-
- pascal void
- LNotificationTask::TaskUPP(
- SNoteTaskT *inNoteTaskPtr)
- {
- #if !GENERATINGCFM
- Int32 oldA5 = ::SetA5(inNoteTaskPtr->A5World);
- #endif
-
- inNoteTaskPtr->noteTask->ExecuteTask();
-
- #if !GENERATINGCFM
- ::SetA5(oldA5);
- #endif
- }
-
-
- // ---------------------------------------------------------------------------
- // • ContinueTask
- // ---------------------------------------------------------------------------
- // Nothing to do with a notification!!!
-
- void
- LNotificationTask::ContinueTask()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartTaskSelf
- // ---------------------------------------------------------------------------
- // Most of the time, with a Notification, there is nothing to do...
-
- void
- LNotificationTask::StartTaskSelf()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ExecuteTaskSelf
- // ---------------------------------------------------------------------------
- // Most of the time, with a Notification, there is nothing to do...
-
- void
- LNotificationTask::ExecuteTaskSelf(
- Boolean &ioLastCall)
- {
- Boolean sameProcess = false;
- ProcessSerialNumber currentProcess;
-
-
- ::GetFrontProcess(¤tProcess);
- ::SameProcess(&mApplicationPSN, ¤tProcess, &sameProcess);
-
- if(sameProcess) {
-
- mUserHasSeenNote = true;
- ioLastCall = true;
-
- } else {
-
- StartIdling();
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • StopTaskSelf
- // ---------------------------------------------------------------------------
- // Most of the time, with a Notification, there is nothing to do...
-
- void
- LNotificationTask::StopTaskSelf()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • SpendTime
- // ---------------------------------------------------------------------------
-
- void
- LNotificationTask::SpendTime(
- const EventRecord &/*inMacEvent*/)
- {
- Boolean sameProcess = false;
- ProcessSerialNumber currentProcess;
-
-
- ::GetFrontProcess(¤tProcess);
- ::SameProcess(&mApplicationPSN, ¤tProcess, &sameProcess);
-
- if(sameProcess) {
-
- mUserHasSeenNote = true;
- StopTask();
- StopIdling();
- }
- }
-